import ViewBase from '../../engine/ViewBase';
import { UIHelper } from '../util/UIHelper';
const { ccclass, property } = cc._decorator;

@ccclass
export class ViewCheck extends ViewBase {

    public static Dialog_Type = {
        All: 0,
        OK: 1,
    }

    private txtIntro: cc.Label;
    private tips: string;
    private callback: Function;
    private btnCancel: cc.Node
    private btnClose: cc.Node
    private dialogType: number = ViewCheck.Dialog_Type.OK

    private init() {
        if (!this.isInit) {
            this.isInit = true;
            let controlUI: cc.Node = this.findChild(this.node, "controlUI")
            this.txtIntro = this.getChild(this.node, "txtIntro", cc.Label);
            let btnOK: cc.Node = this.findChild(controlUI, "btnOK");
            UIHelper.onAddEvent(btnOK, () => {
                this.closeView()
                this.callback && this.callback(true);
            })
            this.btnCancel = this.findChild(controlUI, "btnCancel");
            UIHelper.onAddEvent(this.btnCancel, () => {
                this.closeView()
                this.callback && this.callback(false);
            })
            let btnClose: cc.Node = this.findChild(this.node, "btnClose");
            this.btnClose = btnClose;
            UIHelper.onAddEvent(btnClose, () => {
                this.closeView()
                this.callback && this.callback(false);
            })
        }
    }

    onEnable() {
        this.init();
    }

    public onInitChild(initParam: object) {
        this.init()
        this.tips = initParam["tips"];
        this.callback = initParam["callback"];
        this.dialogType = initParam["dialogType"]
        if (this.dialogType == ViewCheck.Dialog_Type.All) {
            this.btnCancel.active = true
            this.btnClose.active = true
        } else if (this.dialogType == ViewCheck.Dialog_Type.OK) {
            this.btnCancel.active = false
            this.btnClose.active = false
        }
        this.txtIntro.string = "" + this.tips;
    }


}

